#include <SFML/Graphics/RenderWindow.hpp>
#include <nice2d/macros.h>
#include <nice2d/background.h>
#include <nice2d/imagedescriptor.h>
#include <nice2d/util.h>
#include <nice2d/animation.h>
#include <nice2d/tilemap.h>
#include <nice2d/components/imagemanager.h>
#include <nice2d/actions/sequenceaction.h>
#include <nice2d/piece/piecescene.h>
#include <nice2d/components/attributetable.h>
#include <nice2d/spritetextdecorator.h>
#include <nice2d/spriteimagedecorator.h>
#include <nice2d/spriteattributedecorator.h>

#define SCENE_WIDTH  900.0f
#define SCENE_HEIGHT 680.0f

class UnitScene : public PieceScene
{
public:
    void onInitialed()override
    {
        setSceneBox({0.0f, 0.0f, SCENE_WIDTH, SCENE_HEIGHT});

        auto sprite = std::make_shared<Sprite>();
        sprite->setSize(64,64);
        sprite->setRounded(6.0f,24);

        setBackgroundColor(sf::Color::Blue);
        sprite->setBackgroundColor(sf::Color::Black);
        sprite->setPosition(200,200);
        addChild(sprite);

        TextOption option;
        option.characterSize = 16.0f;

        auto text = std::make_shared<SpriteTextDecorator>(option);
        text->setText("Infantry");
        text->setHAlignment(HMode_Center);
        text->setVAlignment(VMode_Top);
        text->setYOffset(3.0f);
        text->setTextColor(sf::Color::Red);
        sprite->addDecorator(text);

        auto icon1 = std::make_shared<SpriteImageDecorator>();
        icon1->setImage("./../data/icon/nato/units/infantry.png",{});
        icon1->setColor(sf::Color::Green);
        icon1->setScale(0.5f);
        sprite->addDecorator(icon1);

        auto icon2 = std::make_shared<SpriteImageDecorator>();
        icon2->setImage("./../data/icon/nato/sizes/group.png",{});
        icon2->setColor(sf::Color::Green);
        icon2->setScale(0.5f);
        sprite->addDecorator(icon2);

#define ATTRIBUTE_ATTACK  0
#define ATTRIBUTE_DEFENSE 1
#define ATTRIBUTE_MOVE    2

        auto table = GET_COMPONENT(sprite,AttributeTable1D);
        table->add(ATTRIBUTE_ATTACK,3);
        table->add(ATTRIBUTE_DEFENSE,2);
        table->add(ATTRIBUTE_MOVE,4);

        auto attributedecorator = std::make_shared<SpriteAttributeDecorator>(option);
        attributedecorator->setTextColor(sf::Color::Red);
        attributedecorator->setHAlignment(HMode_Center);
        attributedecorator->setVAlignment(VMode_Bottom);
        attributedecorator->setYOffset(-5.0f);
        attributedecorator->setAttibutes({ATTRIBUTE_ATTACK,ATTRIBUTE_DEFENSE,ATTRIBUTE_MOVE});
        sprite->addDecorator(attributedecorator);

        option.characterSize = 12;
        auto text2 = std::make_shared<SpriteTextDecorator>(option);
        text2->setText("A");
        text2->setHAlignment(HMode_Left);
        text2->setVAlignment(VMode_Center);
        text2->setXOffset(3.0f);
        text2->setRotate(90.0f);
        text2->setTextColor(sf::Color::Yellow);
        sprite->addDecorator(text2);

    }
private:
};

DECLARE_MAIN_FUNCTION_WITH_SCENE(SCENE_WIDTH, SCENE_HEIGHT, "unit23", UnitScene)
